import { BasicColumn, FormSchema } from '/@/components/Table';
import { Tag } from "ant-design-vue";
import { h, } from 'vue';

export const columns: BasicColumn[] = [
  {
    title: '级别',
    dataIndex: 'level',
    customRender: ({ value }) => {
      const color = 'green';
      let text = ''
      switch (value) {
        case 1: text = '省'; break;
        case 2: text = '市'; break;
        case 3: text = '区'; break;
        case 4: text = '乡镇街道'; break;
        case 5: text = '村社区'; break;
      }
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '上级编码',
    dataIndex: 'parentCode',
  },
  {
    title: '编码',
    dataIndex: 'areaCode',
  },
  {
    title: '名称',
    dataIndex: 'name',
  },
  {
    title: '组合全称',
    dataIndex: 'mergerName',
  },
  {
    title: '邮编',
    dataIndex: 'zipCode',
  },
  {
    title: '拼音',
    dataIndex: 'pinyin',
  },
  {
    title: '经度',
    dataIndex: 'lng',
  },
  {
    title: '纬度',
    dataIndex: 'lat',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'level',
    label: '级别',
    component: 'Select',
    colProps: { span: 6, },
    componentProps: {
      options: [
        {
          label: '省',
          value: 1,
        },
        {
          label: '市',
          value: 2,
        },
        {
          label: '区',
          value: 3,
        },
        {
          label: '乡镇街道',
          value: 4,
        },
        {
          label: '村社区',
          value: 5,
        },
      ],
    },
  },
  {
    field: 'parentCode',
    label: '上级编码',
    component: 'Input',
    colProps: { span: 6, },
  },
  {
    field: 'keyword',
    label: '关键字',
    component: 'Input',
    componentProps: {
      placeholder: '请输入名称/编码',
    },
    colProps: { span: 6, lg: { span: 6, offset: 0 }, sm: { span: 10, offset: 0 }, xs: { span: 16, offset: 0 } },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'pcode',
    label: 'pcode',
    required: false,
    component: 'Input',
    show: false,
  },
  {
    field: 'name',
    label: '名称',
    required: true,
    component: 'Input',
    rules: [
      {
        required: true,
        whitespace: true,
        message: '名称不能为空！',
      },
      {
        max: 20,
        message: '字符长度不能大于20！',
      },
    ],
    colProps: { span: 24 },
  },
  {
    field: 'code',
    label: '编码',
    required: true,
    component: 'Input',
    colProps: { span: 24 },
  },
];
